const TWEEN = require("@tweenjs/tween.js");
export const scroll = ({
  direction = "top",
  distance,
  el,
  duration = 500
}) => {
  let directionKey = "scrollTop";
  let forward = 1;
  if (direction == "left" || direction == "right") {
    directionKey = "scrollLeft"
  };
  if (direction == "left" || direction == "top") {
    forward = -1;
  }
  let current = el[directionKey];
  let option = {};
  option[directionKey] = current + forward * distance;
  const ani = new TWEEN.Tween(el)
    .to(option,
      duration
    )
    .start();

  function animate(duration) {
    requestAnimationFrame(animate);
    ani.update(duration);
  }
  requestAnimationFrame(animate);
}
